package org.example.tlias.controller;

import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.example.tlias.pojo.Dept;
import org.example.tlias.pojo.Result;
import org.example.tlias.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Slf4j
@RequestMapping("/depts")
@RestController
public class DeptController {
    @Autowired
    private DeptService deptService;


    @GetMapping
    public Result list() {
        log.info("查询所有部门数据");
        List<Dept> deptList = deptService.findAll();
        return Result.success(deptList);
    }

    @DeleteMapping
    public Result delete( Integer id) {
       log.info("删除部门数据{}",id);
        deptService.deleteById(id);
        return Result.success();
    }

    @PostMapping
    public Result add(@RequestBody Dept dept) {
        log.info("添加部门数据{}", dept);
        deptService.add(dept);
        return Result.success();
    }

    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable Integer id) {
       log.info("根据ID查询部门数据：{}", id);
        Dept dept = deptService.getById(id);

        return Result.success(dept);
    }

    @PutMapping
    public Result update(@RequestBody Dept dept) {
        log.info("更新部门数据{}", dept);
        deptService.update(dept);
        return Result.success();
    }



}






